class Solution(object):
    def countCollisions(self, directions):
        n = len(directions)
        left = 0
        right = n - 1
        while left < n:
            if directions[left] == 'L':
                left += 1
            else:
                break
        while right >= 0:
            if directions[right] == 'R':
                right -= 1
            else:
                break
        ans = 0
        if left >= right:
            return 0
        for i in range(left, right + 1):
            if directions[i] != 'S':
                ans += 1
        return ans

